#pragma once

#include "Widgets/Widget.h"

#include "HorizontalSplitableWidget.m.h"

class RHorizontalPositionerWidget;

//like horizontal positioner widget, but have allow user change size of widget by mouse
//there is two kind of widget in this widget,
//the sub widget that can be contianer of user widget, named "Slot"
//the mouse widget that can be used to change the size of the two widgets, named "Spliter"

//there is a example show how to add sub widgets :
// auto SplitableWidget=NewWidget<RHorizontalSplitableWidget>(ParentWidget);
// auot MyWidget=NewWidget<RMyWidget>(SplitableWidget->AddSlot());
// auto MyWidget2=NewWidget<RMyWidget>(SplitableWidget->AddSlot());
RCLASS()
class WHENGINE_API RHorizontalSplitableWidget : public RWidget
{
    ROBJECT
public:
    RHorizontalSplitableWidget();

    TWidgetAttribute<float> Spacing=4;

    RWidgetPtr AddSlot(float SizeWeight=1.0f);
    RWidgetPtr GetSlot(int32_t Index);
    void RemoveSlot(int32_t Index);
protected:

    //container of all Spliters
    TWeakObjectPtr<RWidget> SpliterContainer;
    TWeakObjectPtr<RHorizontalPositionerWidget> SlotContainer;

    struct SSlot
    {
        TWeakObjectPtr<RWidget> Widget;

        //spliter that before this slot
        //first slot have no former spliter
        TWeakObjectPtr<RWidget> FormerSpliter;

        float SizeWeight=1.0f;
    };
    
    TVector<SSlot> Slots;

    virtual void CalculateChildrenPresentPositionAndSize() override;

    float StartDragX=0;
    float StartDragTotalSizeWeight=0;

    float StartDragFormerSizeWeight=0;
    float StartDragLatterSizeWeight=0;

    float StartDragFormerLatterSize=0;
};